ArcPad Scripting Object Model
AddXYValues Example
Send Feedback
ArcPad Scripting Object Model Reference > ArcPad Scripting Samples > AddXYValues Example

Glossary Item Box

Description

Populates a point layer's X and Y attributes with each point feature's geographic X and Y coordinates.

VBScript Code

Copy Code
Sub AddXYValues(p_pRS, p_XFieldName, p_YFieldName)
      Dim pFields
      Set pFields = p_pRS.Fields
      p_pRS.MoveFirst
      Do While Not p_pRS.EOF
              pFields(p_XFieldName).Value = pFields.Shape.X
            pFields(p_YFieldName).Value = pFields.Shape.Y
            p_pRS.Update
            p_pRS.MoveNext
      Loop
End Sub
 
'++ here's an example of calling AddXYValues to populate the LATITUDE and LONGITUDE fields of layer 1
Dim pRS
Map.Layers(1).Editable = True
Set pRS = Map.Layers(1).Records
Call AddXYValues(pRS, "LONGITUDE", "LATITUDE")
Set pRS = Nothing
Map.Layers(1).Editable = False

 

JScript Code

Copy Code
function AddXYValues(p_pRS, p_XFieldName, p_YFieldName)
{
      var pFields = p_pRS.Fields;
      p_pRS.MoveFirst();
      while (!p_pRS.EOF)
      {
              pFields(p_XFieldName).Value = pFields.Shape.X;
            pFields(p_YFieldName).Value = pFields.Shape.Y;
            p_pRS.Update();
            p_pRS.MoveNext();
      }
}
 
// here's an example of calling AddXYValues to populate the LATITUDE and LONGITUDE fields of layer 1
Map.Layers(1).Editable = true;
var pRS = Map.Layers(1).Records;
AddXYValues(pRS, "LONGITUDE", "LATITUDE");
pRS = null;
Map.Layers(1).Editable = false;

 

©2012. All Rights Reserved.